package com.camp.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.camp.domain.CYd;
import com.camp.service.ICYdService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 营地Controller
 * 
 * @author ruoyi
 * @date 2024-10-08
 */
@RestController
@RequestMapping("/camp/yd")
public class CYdController extends BaseController
{
    @Autowired
    private ICYdService cYdService;

    /**
     * 查询营地列表
     */
    @PreAuthorize("@ss.hasPermi('camp:yd:list')")
    @GetMapping("/list")
    public TableDataInfo list(CYd cYd)
    {
        startPage();
        List<CYd> list = cYdService.selectCYdList(cYd);
        return getDataTable(list);
    }

    /**
     * 导出营地列表
     */
    @PreAuthorize("@ss.hasPermi('camp:yd:export')")
    @Log(title = "营地", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CYd cYd)
    {
        List<CYd> list = cYdService.selectCYdList(cYd);
        ExcelUtil<CYd> util = new ExcelUtil<CYd>(CYd.class);
        util.exportExcel(response, list, "营地数据");
    }

    /**
     * 获取营地详细信息
     */
    @PreAuthorize("@ss.hasPermi('camp:yd:query')")
    @GetMapping(value = "/{ydId}")
    public AjaxResult getInfo(@PathVariable("ydId") String ydId)
    {
        return success(cYdService.selectCYdByYdId(ydId));
    }

    /**
     * 新增营地
     */
    @PreAuthorize("@ss.hasPermi('camp:yd:add')")
    @Log(title = "营地", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CYd cYd)
    {
        return toAjax(cYdService.insertCYd(cYd));
    }

    /**
     * 修改营地
     */
    @PreAuthorize("@ss.hasPermi('camp:yd:edit')")
    @Log(title = "营地", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CYd cYd)
    {
        return toAjax(cYdService.updateCYd(cYd));
    }

    /**
     * 删除营地
     */
    @PreAuthorize("@ss.hasPermi('camp:yd:remove')")
    @Log(title = "营地", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ydIds}")
    public AjaxResult remove(@PathVariable String[] ydIds)
    {
        return toAjax(cYdService.deleteCYdByYdIds(ydIds));
    }
}
